package com.dnxh.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dnxh.entity.Department;
import com.dnxh.entity.common.PageContext;
import com.dnxh.entity.common.PageRequest;
import com.dnxh.mapper.DepartmentMapper;
import com.dnxh.service.DepartmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 枳湫
 * @Time 2022/4/6 18:20
 * @Describe Basic_jar
 **/
@Slf4j
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
	
	@Resource
	private DepartmentMapper departmentMapper;
	
	@Override
	public PageContext<Department> search (PageRequest request) {
		if (request.getPageSize () == 0){
			return new PageContext<Department> ()
					.setList (list ())
					.setCount (0L);
		}else {
			IPage<Department> iPage = new Page<Department> ()
					.setSize (request.getPageSize ())
					.setCurrent (request.getPageNum ());
			IPage<Department> list = page (iPage, Wrappers.lambdaQuery ());
			return new PageContext<Department> ()
					.setList (list.getRecords ())
					.setCount (iPage.getTotal ());
		}
	}
	
	@Override
	public void deleteDepartment (Long id) {
		departmentMapper.deleteDepartment (id);
	}
}
